<?php
/*
 * class.list.php
 * 用户列表类
 * @version 0.1
 * @author samuel
 * @date 2009-05-18
 */
include_once 'class.userBase.php';
class user_list extends userBase  {
    private $step;
    private $classname;
    private $tpl_file;

    function  __construct($core) {
        parent::__construct();

        //参数处理
        $this->step = $this->params['step'];
        if(!$this->step) $this->step = "list";
        $this->classname = strtolower(trim(get_class($this)));
        $this->tpl_file = $this->classname . "_" . $this->step . ".html";

        $this->run();
    }

    function run(){
        var_dump($this->step);
        switch($this->step){
            case 'list':
                $page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_join[] = array('table'=>'fun_user_group', 'table_short'=>'b', 'on'=>'a.`UserGroupID`=b.`UserGroupID`');
                $arr_join[] = array('table'=>'fun_seller_province', 'table_short'=>'c', 'on'=>'a.`UserBirthdayProvince`=c.`SellerProvinceID`');
                $arr_join[] = array('table'=>'fun_seller_city', 'table_short'=>'d', 'on'=>'a.`UserBirthdayCity`=d.`SellerCityID`');
                $arr_infos = $this->getInfoList(array('table'=>'fun_user', 'primary'=>'UserID'), $arr_join, "", array("UserID"=>"desc"), $arr_limit);
                $arr_lists = $arr_infos['list'];
                $pager = $arr_infos['pager'];
                $this->core->tpl->assign('arr_lists', $arr_lists);
                $this->core->tpl->assign('pager', $pager);
                break;
            case 'add':
                $groups = $this->getUserGroupList();
                $this->core->tpl->assign('groups', $groups);
                $provinces = $this->getSellerAllProvinceList();
                $this->core->tpl->assign('provinces', $provinces);
                $cities = $this->getSellerAllCityList();
                $this->core->tpl->assign('cities', $cities);
                break;
            case 'do_add':
                $add_info['UserNickName'] = $this->params['UserNickName'];
                $add_info['UserPassword'] = $this->params['UserPassword'];
				$add_info['UserMobile'] = $this->params['UserMobile'];
                $add_info['UserGroupID'] = trim(implode(',',$this->params['UserGroupID']), ',');
                $add_info['UserEmail'] = $this->params['UserEmail'];
                $add_info['UserSex'] = $this->params['UserSex'];
                $add_info['UserQQ'] = $this->params['UserQQ'];
                $add_info['UserMSN'] = $this->params['UserMSN'];
                $add_info['UserBlood'] = $this->params['UserBlood'];
                $add_info['UserBirthday'] = $this->params['UserBirthday'];
                $add_info['UserBirthdayProvince'] = $this->params['UserBirthdayProvince'];
                $add_info['UserBirthdayCity'] = $this->params['UserBirthdayCity'];
                $add_info['UserMarry'] = $this->params['UserMarry'];

                $tag = $this->addNewInfo('fun_user', $add_info);
                if(!$tag){
                    $this->core->utility->messagePrompt($this->error);
                }
                $this->core->utility->messagePrompt('添加成功!');
                return;
                break;
            case 'edit':
                $groups = $this->getUserGroupList();
                $this->core->tpl->assign('groups', $groups);
                $provinces = $this->getSellerAllProvinceList();
                $this->core->tpl->assign('provinces', $provinces);
                $cities = $this->getSellerAllCityList();
                $this->core->tpl->assign('cities', $cities);
                $id = $this->params['id'];
                $info = $this->getInfo(array('table'=>'fun_user', 'primary'=>'UserID'),$id);
                $info['userGroups'] = @explode(',', $info['UserGroupID']);
                //var_dump($info);
				$this->core->tpl->assign('info', $info);
                break;
			case 'do_edit':
				$id = $this->params['id'];
				$edit_info['UserNickName'] = $this->params['UserNickName'];
                $edit_info['UserPassword'] = $this->params['UserPassword'];
				$edit_info['UserMobile'] = $this->params['UserMobile'];
                $edit_info['UserGroupID'] = trim(implode(',',$this->params['UserGroupID']), ',');
                $edit_info['UserEmail'] = $this->params['UserEmail'];
                $edit_info['UserSex'] = $this->params['UserSex'];
                $edit_info['UserQQ'] = $this->params['UserQQ'];
                $edit_info['UserMSN'] = $this->params['UserMSN'];
                $edit_info['UserBlood'] = $this->params['UserBlood'];
                $edit_info['UserBirthday'] = $this->params['UserBirthday'];
                $edit_info['UserBirthdayProvince'] = $this->params['UserBirthdayProvince'];
                $edit_info['UserBirthdayCity'] = $this->params['UserBirthdayCity'];
                $edit_info['UserMarry'] = $this->params['UserMarry'];
				$this->updateInfo('fun_user', 'UserID', $id, $edit_info);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('更新成功！');
				}
				return;
				break;
			case 'del':
				$id = $this->params['id'];
				$this->delInfo('fun_user_group', 'UserGroupID', $id);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
				return;
				break;
			case 'batch_del':
                $ids = $this->params['checkboxes'];
                if(is_array($ids)){
                    foreach($ids as $id){
                        $this->delInfo('fun_user', 'UserID', $id);
                    }
                }
                if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
                return;
                break;
			case 'search':
				$search_cname = $this->params['search_cname'];
				$search_cno = $this->params['search_cno'];
				$search_pname = $this->params['search_pname'];
				$search_url_append = "&step=".$this->step."&search_cname=".$search_cname."&search_cno=".$search_cno."&search_pname=".$search_pname;
				$arr_filter = array();
				if($search_cname){
					$arr_filter[] = array('attr'=>'SellerCityNameCN', 'value'=>$search_cname, 'match'=>'like');
				}
				if($search_cno){
					$arr_filter[] = array('attr'=>'SellerCityNo', 'value'=>$search_cno, 'match'=>'like');
				}
				if($search_pname){
					$arr_filter[] = array('attr'=>'SellerProvinceNameCN', 'value'=>$search_pname, 'match'=>'like', 'join'=>'b');
				}
				$page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . $search_url_append;
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_cities_info = $this->getSellerCityList($arr_filter, array("SellerCityID"=>"desc"), $arr_limit);
                $arr_cities = $arr_cities_info['list'];
                $pager = $arr_cities_info['pager'];
                $this->core->tpl->assign('arr_cities', $arr_cities);
                $this->core->tpl->assign('pager', $pager);
				//共用一个模板
				$this->tpl_file = "seller_city_list.html";
				break;
        }
        $this->core->tpl->display($this->tpl_file);
    }

}
?>